"""
            列表                          元组                               字符串                   集合                                    字典
表达       [1,"xy",{k:1},[1,2],(1,2)]     (1,"xy",{k:1},[1,2],(1,2))        "12 yxyxyx"         {1,2,"xy",[1,2],(1,2),{k:1}}               {"xy":1,22:{1,2},1,[2,"ww"]}

下标索引    l[0][-1]                        t[0][-1]

可修改     l[1]="ww"

插入      l.insert(2,"ww")

追加      l.append("xy")                  t.append("xy")                                           set.add("xy")                          dict = {"xy":11,"ww":3}
         l.extend("ww","xy")
         l2.extend(l1)

删除      del l[0][-1]                    del t[0][-1]                                             set.remove("xy")                      dict.pop("xy")
         l.pop(1)                                                                                 set.pop()--删除最后一个
         l.remove("xy")

清空      l.clear()                                                                               set.clear()                           dict.clear()

统计元素   l.count("xy")                   t.count("xy")                  count("xy")                                                   获取全部key：dict.keys()  dict.values()

统计所有元素   len(l)                       len(t)                         len(str)                  len(set)                            len(dict)

查找下标      l.index("xy")                t.index("xy")

while循环    while index <len(l):          while  index < len(t):         while num < len(str):
                elemen = l[index]              elemen = t[index]

for循环     for elemen in l:              for elemen in t:                for elemen in str:         for elemen in set:                 for elemen in dict:
                                                                                                                                           value = dict[elemen]
替换                                                                        str.replace("xy","好")

分裂                                                                        str.split("")                                              for name in dict
                                                                                                                                          dict[name]["分数"] += 10
去除首尾字符串                                                                str.strip("xy")

切片                                                                        str[0][4::-1]

反转                                                                        str[::-1]

差集              1中减去和2重复的           set3 = set1.difference(set2)
                 1中保留不重复的，并更新1     set3 = set1.difference_update(set2)
合并集合                                   set3 = set1.union(set2)
=====================================================================================================================
全部可用：
          max     (l、t、str、set、dict）
          min     (l、t、str、set、dict）
          len     (l、t、str、set、dict）
          sorted  (l、t、str、set、dict）
          sorted  (l、t、str、set、dict,     reverse =True）
"""
# -----------------------------------------------------------------          列表list（可修改）
my_list = [2,3,4,2,2,2,[1,2,3],[4,5,6],[7,8,9],"jiay",[1,2,3],"jiay"]
print(my_list[2][2])
print(my_list[0][0])
print(my_list[-1][-1])
# -----------------------------------------------------------               列表的常用方法
# index方法
my_list = ["list","ny","jiay"]
index = my_list.index("list")
print(index)

# # 修改元素
my_list[1] = "wo"
print(my_list)

# # 插入
my_list.insert (2,"heima")
print(my_list)

# # 追加元素单个和多个
my_list.append("nihao")
print(my_list)

my_list.extend(["word","程序员"])
print(my_list)

my_list2 = [23,45,67]
my_list.extend(my_list2)
print(my_list)

# # 删除元素
del my_list[0]
print(my_list)

element = my_list.pop(1)
print(my_list)
print(element)

my_list.remove("ny")
print(my_list)

# 清空列表
my_list.clear()
print(my_list)

# 统计列表中的元素
count = my_list.count(2)
print(count)

count = my_list.count([1,2,3])
print(count)

count = my_list.count("jiay")
print(count)

# # 统计列表所有元素
count = len(my_list)
print(count)

my_list = [21,25,21,23,22,20]
my_list.append(31)
print(my_list)

my_list.extend([29,33,30])
print(my_list)

my_list.remove(21)
print(my_list)

del my_list[1]
print(my_list)

del my_list[-1]
print(my_list)

index = my_list.index(31)
print(index)
# --------------------------------------------------------      while   和   for 取列表中的元素（遍历/迭代操作）
def list_while_func():
    my_list= [1,"hello","黑马"]
    index = 0
    while index < len(my_list):
        print(my_list[index])
        index += 1
list_while_func()

my_list = [1,2,"zhangsan",4,5,6,7,8]
def list_for_func():
    for elemen in my_list:
        print(elemen)
list_for_func()
# -----------------------------------------------------
my_list = [1,2,3,4,5,6,7,8,9,10]
new_list= []
def while_list():
    index = 0
    while index < len(my_list):
        elemen = my_list[index]
        if elemen % 2 == 0:
            new_list.append(elemen)
        index += 1
    print(new_list)

while_list()

#
# def list_for_func():
def for_list():
    index = 0
    for elemen in my_list:
        if elemen % 2 == 0:
            new_list.append(elemen)
    print(new_list)

for_list()
# ----------------------------------------------------------------               元组tuple（不可修改，里面的list可修改）
t1 = (1,2,"hello","黑马")
t2 = tuple()
t3 = ()
t4 = (1,)
t5 = ((1,2),9,(4,6),(7,8,0),9,"黑马",9,9)

def while_t():
    num = 0
    while num < len(t5):
        elemen = t5[num]
        print(elemen)
        num += 1
while_t()

def for_t():
    for elemen in t5:
        print(f"for:{elemen}")

for_t()
print(type(t1))
print(type(t2))
print(type(t3))
print(type(t4))
num = t5[2][1]
print(type(t5))
print(t5[3])

index = t5.index("黑马")
print(index)
print(len(t5))

count = t5.count(9)
print(count)

t = (1,2,3,4,5,[1,4,5,6,8],"黑马")
t[5][1]=8
print(t)

t = ('周杰伦',11,['football','music'])
# 元组下标
index = t.index(11)
print(index)

print(t[0])
# 元组中的列表删除元素
del t[2][0]
print(t)

t[2].remove("football")
print(t)
# 元组中的列表增加元素
t[2].append("coding")
print(t)
# -------------------------------------------------------------           字符串(不可修改)
str = "itheima and itcast"

# 字符串中的元素替换
new_str = str.replace("it","黑马")
print(new_str)

# 字符串中的元素分裂
new_str = str.split(" ")
print(new_str)

new_str = str.split("i")
print(new_str)
print(str)

str = "134itheima is a cast1234"
new_str = str.strip()
# print(new_str)

new_str = str.strip("123") # ---去除首尾的字符串
print(new_str)
count = str.count("t")
print(count)
print(len(str))

str = "132 4 5 hrima "
for elemen in str:
    print(elemen)

def while_str():
    num = 0
    while num < len(str):
        print(f"while_str:{str[num]}")
        num += 1
while_str()
# ----------------------------------------------------         字符串的统计、替换、分裂
str = "itheima itcast boxuegu"
# count =str.count("it")
# print(count)

new_str = str.replace(" ","|")
print(new_str)
#
new_str1 = new_str.split("|")
print(new_str1)
# ------------------------------------------------            字符串的切片
str = "万过薪月，员序程马黑来，nohtyP学"
new_str = str.split("，")
# print(new_str)
# new_str1 = new_str[1]
# print(new_str1)
new_str2 = new_str[1][4::-1]
new_str2 =new_str[::-1]               # --- 字符串反转
print(new_str2)
# ----------------------------------------------------------------------集合（无序，不支持下标索引；序列、元组、字符串是有序的）
set = {"itheima","cast","传智教育"}
# 添加新元素
set.add("加油")
print(set)

# 移除元素
set.remove("cast")
print(set)

# 随机删除一个元素
set.pop()
print(set)

# 清空集合
set.clear()
print(set)

# 取2个集合的差集
set1 = {1,2,3,"heima","zz",8,9}
set2 = {1,4,"zz",9}
set3 = set1.difference(set2)# ------1中减去和2重复的
print(set3)

# 消除2个集合的差集
set3 = set1.difference_update(set2) # -----1去除和2重复的后，更新1（保留不重复的）
print(set1)
print(set2)

# #合并集合
set3 = set1.union(set2)
print(set3)

# 统计集合元素数量
num1 =len(set1)
num2 =len(set2)
print(num1)
print(num2)

# 集合的遍历---------不能用while循环，没有下标索引
def for_set():
    for elemen in set1:
        print(f"set1: {elemen}")
for_set()

# --------------------------------------------------------
list = ['黑马程序员','传播智科','黑马程序员','传播智科','itheima','itcast','itheima','itcast','best']
# print(list)
set = set()
# print(set)
for elemen in list:
    # print(elemen)
    set.add(elemen)
print(f"新的set: {set}")
# ----------------------------------------------------------------------------- 字典(没有下标索引）
dict1 = {"王":22,"张":23,"周":21}
dict2 = {}
dict3 = dict()
print(f"dict1的值为：{dict1}，类型为：{type(dict1)}")
print(f"dict2的值为：{dict2}，类型为：{type(dict2)}")
print(f"dict3的值为：{dict3}，类型为：{type(dict3)}")

#基于key获得value
age = dict1["王"]
print(age)

#嵌套字典获取value
dict = {
    "王":{
        "语文":77,
        "数学":66,
        "外语":33,
    },
    "周":{
        "语文":88,
        "数学":86,
        "外语":55
    },
    "张":{
        "语文":41,
        "数学":22,
        "外语":99
    }
}
score = dict["王"]["语文"]
print(score)
# -------------------------------------------------------------
# 添加及更新元素
dict ={"周":22,"张":21,"李":24}

dict["王"]=25
print(dict)

dict["周"]=33
print(dict)

# 删除元素
dict.pop("周")
print(dict)

# 清空元素
dict.clear()
print(dict)

# 获取全部key
keys = dict.keys()
print(keys)

# 遍历字典
def for_dict():
    for elemen in dict:
        value = dict[elemen]
        print(elemen)
        print(value)
for_dict()

# 统计元素数量
print(f"元素数量：{len(dict)}")
# -------------------------------------------------------          升职加薪
dict = {"王":{"部门":"科技部","工资":3000,"级别":1},
        "周":{"部门":"市场部","工资":5000,"级别":2},
        "林":{"部门":"市场部","工资":7000,"级别":3},
        "张":{"部门":"科技部","工资":4000,"级别":1},
        "刘":{"部门":"市场部","工资":6000, "级别":2}}
#
for name in dict:
    if dict[name]["级别"] == 1:
        dict[name]["级别"] += 1
        dict[name]["工资"] += 1000
print(dict)
# -----------------------------------------------------------------            数据容器的通用功能
my_list = [2,1,4,5,3,]
my_str ="bgacdfe"
my_tuple = (5,3,2,1,4)
my_set = {4,3,5,1,2}
my_dict ={"key3":1,"key5":2,"key2":3,"key1":4,"key4":5}

# len元素个数
print(f"列表元素个数{len(my_list)}")
print(f"字符串元素个数{len(my_str)}")
print(f"元组元素个数{len(my_tuple)}")
print(f"集合元素个数{len(my_set)}")
print(f"字典元素个数{len(my_dict)}")
# # max最大元素
print(f"列表元素个数  {max(my_list)}")
print(f"字符串元素个数 {max(my_str)}")
print(f"元组元素个数  {max(my_tuple)}")
print(f"集合元素个数  {max(my_set)}")
print(f"字典元素个数  {max(my_dict)}")
# min最小元素
print(f"列表元素个数  {min(my_list)}")
print(f"字符串元素个数 {min(my_str)}")
print(f"元组元素个数  {min(my_tuple)}")
print(f"集合元素个数  {min(my_set)}")
print(f"字典元素个数  {min(my_dict)}")
# sort 排序
print(f"列表:  {sorted(my_list)}")
print(f"字符串:{sorted(my_str)}")
print(f"元组:  {sorted(my_tuple)}")
print(f"集合:  {sorted(my_set)}")
print(f"字典:  {sorted(my_dict)}")
 # 倒序
print(f"列表:  {sorted(my_list ,reverse = True)}")
print(f"字符串:{sorted(my_str   ,reverse = True)}")
print(f"元组:  {sorted(my_tuple,reverse = True)}")
print(f"集合:  {sorted(my_set  ,reverse = True)}")
print(f"字典:  {sorted(my_dict ,reverse = True)}")

# ----------------------------------------------------------------------------   函数的多种参数使用形式
# 位置参数
def user_info(name, nn,age,gender):
    print(f"您的名字是{name}：年龄是{age}：性别是{gender}")
# user_info('Tom',20,'男')
# # 关键字参数（键=值）
# user_info(name='Tom',age=20,gender='男' )
user_info('Tom','jems',age=20,gender='男')# ----------位置参数必须在前面，且匹配参数顺序
#
# # 缺省参数（默认值）
# def user_info(name, nn,age,gender='男'):# ------------缺省参数必须在最后
# 不定长参数（位置传递）
def user_info(*args):# --------------随意输入，将以元组存在
    print(args)
# # 不定长参数（位置传递）
def user_info(**kwargs):# -------------按照键值对输入（key=value），将以字典存在kw=key word
    print(kwargs)
# -----------------------------------------------------------------------                  函数作为参数传递
def test(computer):
    result =computer(1,2)
    print(f"computer的类型：{type(computer)}")
    print(result)
def computer(x,y):
    return x + y
test(computer)
# -----------------------------------------------------------------------             lambda 匿名函数
def test(computer):
    result =computer(1,2)
    print(f"结果是：{result}")
test(lambda x, y : x+y)